﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     FeedBack业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class FeedBackSqlMapDao : BaseSqlMapDao, IFeedBackDao
    {
        private static FeedBackSqlMapDao instance = null;
        private static object syncRoot = new object();

        private FeedBackSqlMapDao()
        {
            //
            // TODO: 此处添加FeedBackSqlMapDao的构造函数
            //
        }
        public static IFeedBackDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new FeedBackSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFeedBackByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<FeedBack> GetList()
        {
            try
            {
                return ExecuteQueryForList<FeedBack>("SelectFeedBack", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<FeedBack> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<FeedBack>("SelectFeedBackByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="FeedBackID"></param>
        /// <returns></returns>
        public FeedBack GetDetail(System.String feedbackid)
        {
            try
            {
                return ExecuteQueryForObject<FeedBack>("SelectFeedBack", feedbackid) as FeedBack;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        public object Add(FeedBack feedback)
        {
            //int id = GetId("FeedBack");
            //feedback.FeedBackID = id;

            try
            {
                return ExecuteInsert("InsertFeedBack", feedback);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        public int Update(FeedBack feedback)
        {
            try
            {
                return ExecuteUpdate("UpdateFeedBack", feedback);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="FeedBackID"></param>
        /// <returns></returns>
        public int Delete(System.String feedbackid)
        {
            try
            {
                return ExecuteDelete("DeleteFeedBack", feedbackid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        public int Delete(FeedBack feedback)
        {
            try
            {
                return ExecuteDelete("DeleteFeedBack", feedback.FeedBackID);
            }
            catch
            {
                throw;
            }
        }


        #region##评论分页
        /// <summary>
        /// 评论分页
        /// 创建人：Wilson
        /// 创建时间：2011-10-30
        /// </summary>
        /// <param name="objParamters"></param>
        /// <returns></returns>
        public IList<FeedBack> GetFeedBackPage(object objParamters)
        {
            try
            {
                Handler.FeedBackHandler handler = new Handler.FeedBackHandler();
                ExecuteWithRowDelegate("GetFeedBackPage", objParamters, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.feedbacklist;
                //return ExecuteQueryForList<FeedBack>("GetFeedBackPage", objParamters);
            }
            catch
            {

                throw;
            }
        }
        #endregion


        #region##通过服务ID得到多少人评论
        /// <summary>
        /// 通过服务ID得到多少人评论
        /// 创建人：Wilson
        /// 创建时间：2011-10-31
        /// </summary>
        /// <param name="serviceID"></param>
        /// <returns></returns>
        public int GetFeebBackDistinct(string serviceID)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFeebBackDistinct", serviceID);
            }
            catch
            {

                throw;
            }
        }
        #endregion


        #region##通过服务ID得到评论数
        /// <summary>
        /// 通过服务ID得到评论数
        /// 创建人：Wilson
        /// 创建时间：2011-10-31
        /// </summary>
        /// <param name="servcieID"></param>
        /// <returns></returns>
        public int GetFeebBackCount(string servcieID)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFeebBackCount", servcieID);
            }
            catch
            {

                throw;
            }
        }
        #endregion

        #region##通过用户ID和订单ID得到评论数
        /// <summary>
        /// 通过用户ID和订单ID得到评论数
        /// 创建人：Wilson
        /// 创建时间：2011-11-24
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public int GetFeebBackCountByUserIdAndOrderId(object objParameters)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFeebBackCountByUserIdAndOrderId", objParameters);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region##通过订单ID得到评论
        /// <summary>
        /// 通过订单ID得到评论
        /// 创建人：Wilson
        /// 创建时间：2011-11-24
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public FeedBack GetFeedBackByOrderId(string orderId)
        {
            try
            {
                return ExecuteQueryForObject("SelectFeedBackByOrderId", orderId) as FeedBack;
            }
            catch
            {
                throw;
            }
        }
        #endregion
    }
       
}
